package com.ruoyi.training.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.training.vo.CheckinDetailsResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.training.domain.CheckinRecord;
import com.ruoyi.training.service.ICheckinRecordService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 班级签到记录（学员的实际签到信息）Controller
 *
 * @author WorrilessGo
 * @date 2025-09-24
 */
@RestController
@RequestMapping("/CheckinRecord")
public class CheckinRecordController extends BaseController
{
    @Autowired
    private ICheckinRecordService checkinRecordService;

    /**
     * 查询班级签到记录（学员的实际签到信息）列表
     */
    @RequiresPermissions("CheckinRecord:CheckinRecord:list")
    @GetMapping("/list")
    public TableDataInfo list(CheckinRecord checkinRecord)
    {
        startPage();
        List<CheckinRecord> list = checkinRecordService.selectCheckinRecordList(checkinRecord);
        return getDataTable(list);
    }

    /**
     * 导出班级签到记录（学员的实际签到信息）列表
     */
    @RequiresPermissions("CheckinRecord:CheckinRecord:export")
    @Log(title = "班级签到记录（学员的实际签到信息）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CheckinRecord checkinRecord)
    {
        List<CheckinRecord> list = checkinRecordService.selectCheckinRecordList(checkinRecord);
        ExcelUtil<CheckinRecord> util = new ExcelUtil<CheckinRecord>(CheckinRecord.class);
        util.exportExcel(response, list, "班级签到记录（学员的实际签到信息）数据");
    }

    /**
     * 获取班级签到记录（学员的实际签到信息）详细信息
     */
    @RequiresPermissions("CheckinRecord:CheckinRecord:query")
    @GetMapping(value = "/{checkinRecordId}")
    public AjaxResult getInfo(@PathVariable("checkinRecordId") String checkinRecordId)
    {
        return success(checkinRecordService.selectCheckinRecordByCheckinRecordId(checkinRecordId));
    }

    /**
     * 新增班级签到记录（学员的实际签到信息）
     */
    @RequiresPermissions("CheckinRecord:CheckinRecord:add")
    @Log(title = "班级签到记录（学员的实际签到信息）", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CheckinRecord checkinRecord)
    {
        return toAjax(checkinRecordService.insertCheckinRecord(checkinRecord));
    }

    /**
     * 新增班级签到记录备注
     * lqx
     */
    @PostMapping("/addCheckinRemark")
    public AjaxResult addCheckinRemark(@RequestBody CheckinDetailsResult CheckinDetailsResult)
    {
        return toAjax(checkinRecordService.addCheckinRemark(CheckinDetailsResult));
    }

    /**
     * 修改班级签到记录（学员的实际签到信息）
     */
    @RequiresPermissions("CheckinRecord:CheckinRecord:edit")
    @Log(title = "班级签到记录（学员的实际签到信息）", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CheckinRecord checkinRecord)
    {
        return toAjax(checkinRecordService.updateCheckinRecord(checkinRecord));
    }

    /**
     * 批量修改签到状态
     * lqx
     */
    @PutMapping("/batchUpdate")
    public AjaxResult batchUpdate(@RequestBody List<CheckinDetailsResult> checkinDetailsResultList)
    {
        System.out.println(checkinDetailsResultList.get(0).getCheckinStatus());
        return toAjax(checkinRecordService.batchUpdate(checkinDetailsResultList));
    }

    /**
     * 删除班级签到记录（学员的实际签到信息）
     */
    @RequiresPermissions("CheckinRecord:CheckinRecord:remove")
    @Log(title = "班级签到记录（学员的实际签到信息）", businessType = BusinessType.DELETE)
	@DeleteMapping("/{checkinRecordIds}")
    public AjaxResult remove(@PathVariable String[] checkinRecordIds)
    {
        return toAjax(checkinRecordService.deleteCheckinRecordByCheckinRecordIds(checkinRecordIds));
    }
}
